import React, { Component } from 'react'
import {withRouter} from "react-router-dom"
import "../src/App.css"
import IndexRouter from "./router/indexRouter"
 class App extends Component {
   constructor(props, context) {

     super(props, context)
   this.checkLogin(this.props.location.pathname)
     this.props.history.listen((location)=>{
       this.checkLogin(location.pathname)
     })
   }
  //  componentDidMount(){
  //   this.checkLogin(this.props.location.pathname)
  //  }
  componentDidMount(props, context){
    this.checkLogin(this.props.location.pathname)
  }
  checkLogin =(pathname)=>{
   let isLogin = JSON.parse(localStorage.getItem("isLogin"))
   let arr = ["/Me","/marPro",
  //  "/home",
  "/curser","/News"
  ]
  let result = arr.some(item=>item ===pathname)
  if(result){
    if(!isLogin){
      this.props.history.push("/Login")
    }
  }
  }
  render() {  
    return (
      <div>
        
        <h1>app</h1>
{/*        
       <ul>
          
            <li>
              <NavLink to="/home"  >首页</NavLink>
            </li>  
            <li>
             <NavLink to="/Strategy">攻略</NavLink>
           </li>
           <li>
             <NavLink to="/marPro">婚品</NavLink>
           </li>
          
           <li>
             <NavLink to="/Me">我的</NavLink>
           </li>
        </ul>  
         */}
         
        <IndexRouter></IndexRouter>
      </div>
    )
  }
}
export default withRouter(App) 
